//
//  FSSubmitHeaderView.m
//  fanshu
//
//  Created by mh on 16/3/29.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSSubmitHeaderView.h"

#define welcomeFont setFont(14.0f)
#define detailFont setFont(9.0f)
#define introFont setFont(10.0f)
#define btnClickFont introFont

@interface FSSubmitHeaderView ()
@property(nonatomic,weak)UIImageView *imageView;
@property(nonatomic,weak)UILabel *welcome;
@property(nonatomic,weak)UILabel *detail;
@property(nonatomic,weak)UILabel *intro;
@property(nonatomic,weak)UIButton *btnClick;
@end
@implementation FSSubmitHeaderView

+ (instancetype)submitHeaderView{
    FSSubmitHeaderView *submit = [[self alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 125)];
    return submit;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageNamed:@"img_guide_submit_1"];
        [self addSubview:imageView];
        self.imageView = imageView;
        
        UILabel *welcome = [[UILabel alloc] init];
        welcome.text = @"欢迎你向首页投稿!";
        welcome.font = welcomeFont;
        [self addSubview:welcome];
        self.welcome = welcome;
        //202 202 202
        UILabel *detail = [[UILabel alloc] init];
        detail.text = @"向首页投稿的每一篇文章,都会受到编辑团队的审核回复,祝你成功登上首页哦!";
        detail.textColor = colorOfText(200, 200, 200);
        detail.font = detailFont;
        detail.numberOfLines = 0;
        [self addSubview:detail];
        self.detail = detail;
        //200 200 200
        UILabel *intro = [[UILabel alloc] init];
        intro.textColor = colorOfText(200, 200, 200);
        intro.text = @"点击文章标题进行投稿";
        intro.font = introFont;
        [self addSubview:intro];
        self.intro = intro;
        
        UIButton *btnClick = [[UIButton alloc] init];
        [btnClick setTitleColor:[[UIColor blueColor] colorWithAlphaComponent:0.5f] forState:UIControlStateNormal];
        [btnClick setTitle:@"(查看首页投稿须知)" forState:UIControlStateNormal];
        btnClick.titleLabel.font = btnClickFont;
        [btnClick addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btnClick];
        self.btnClick = btnClick;
    }
    return self;
}

- (void)click{
    if (self.btnOnClick) {
        self.btnOnClick();
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat margin = 10;
    
    CGFloat imageViewX = margin * 2;
    CGFloat imageViewY = margin * 2;
    CGSize imageViewSize = self.imageView.image.size;
    self.imageView.frame = (CGRect){{imageViewX,imageViewY},imageViewSize};
    
    CGFloat welcomeX = CGRectGetMaxX(self.imageView.frame) + margin;
    CGFloat welcomeY = imageViewY + margin * 0.5;
    CGSize welcomeSize = [self.welcome.text sizeWithFont:welcomeFont];
    self.welcome.frame = (CGRect){{welcomeX,welcomeY},welcomeSize};
    
    CGFloat detailX = welcomeX;
    CGFloat detailY = CGRectGetMaxY(self.welcome.frame) + margin;
    CGFloat detailW = ScreenWidth - margin * 2 - detailX;
    CGFloat detailH = [self.detail.text sizeWithFont:detailFont maxW:detailW].height;
    self.detail.frame = CGRectMake(detailX, detailY, detailW, detailH);
    
    CGFloat introX = imageViewX;
    CGFloat introY = CGRectGetMaxY(self.imageView.frame) + margin * 2;
    CGSize introSize = [self.intro.text sizeWithFont:introFont];
    self.intro.frame = (CGRect){{introX,introY},introSize};
    
    CGFloat btnClickX = CGRectGetMaxX(self.intro.frame) + margin * 0.5;
    CGFloat btnClickY = introY;
    CGSize btnClickSize = [self.btnClick.titleLabel.text sizeWithFont:btnClickFont];
    self.btnClick.frame = (CGRect){{btnClickX,btnClickY},btnClickSize};
}

@end
